﻿using SeeSharpTools.Demo.GUI;
using SeeSharpTools.Demo.ReportGeneration;
using Sunny.UI;
using System;
using System.Windows.Forms;

namespace SeeSharpTools.Demo
{
    public partial class FMain : UIHeaderAsideMainFrame
    {
        public FMain()
        {
            InitializeComponent();

            int pageIndex = 1000;
            TreeNode parent = Aside.CreateNode("GUI控件", 0, 24, pageIndex);
            //通过设置PageIndex关联，节点文字、图标由相应的Page的Text、Symbol提供
            Aside.CreateChildNode(parent, AddPage(new FormChart(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormNumeric(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormBoolean(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormString(), ++pageIndex));

            pageIndex = 2000;
            parent = Aside.CreateNode("信号生成", 0, 24, pageIndex);
            //通过设置PageIndex关联，节点文字、图标由相应的Page的Text、Symbol提供
            Aside.CreateChildNode(parent, AddPage(new FormAnalog(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormDigital(), ++pageIndex));

            pageIndex = 3000;
            parent = Aside.CreateNode("信号操作", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormDetrend(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormSmooth(), ++pageIndex));

            pageIndex = 4000;
            parent = Aside.CreateNode("信号测量", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormPulse(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormPhase(), ++pageIndex));

            pageIndex = 5000;
            parent = Aside.CreateNode("动态信号分析", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormHarmonicMeasure(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormSpectrumMeasure(), ++pageIndex));

            pageIndex = 6000;
            parent = Aside.CreateNode("频谱分析", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormPeriodgram(), ++pageIndex));

            pageIndex = 7000;
            parent = Aside.CreateNode("滤波器设计", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormFIRWindow(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormFIRPM(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormIIR(), ++pageIndex));

            pageIndex = 8000;
            parent = Aside.CreateNode("滤波", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormOnline(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormFIRDelay(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormIIRDelay(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormNotch(), ++pageIndex));

            pageIndex = 9000;
            parent = Aside.CreateNode("多速率滤波器", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormDecimate(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormInterpolate(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormResample(), ++pageIndex));

            pageIndex = 10000;
            parent = Aside.CreateNode("报告生成", 0, 24, pageIndex);
            Aside.CreateChildNode(parent, AddPage(new FormExcel(), ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new FormWord(), ++pageIndex));
            
            Header.SetNodeSymbol(Header.Nodes[0], 61502);
            var styles = UIStyles.PopularStyles();
            foreach (UIStyle style in styles)
            {
                Header.CreateChildNode(Header.Nodes[0], style.DisplayText(), style.Value());
            }

            //选中第一个节点
            //Aside.SelectPage(1001);

            Text = Version;
            RegisterHotKey(Sunny.UI.ModifierKeys.Shift, Keys.F8);

            //根据页面索引获取页面
            UIPage page1 = GetPage(1002);
            if (page1 != null)
                page1.Text.WriteConsole();

            Text = "SeeSharpTools.Demo";
        }

        private void Header_MenuItemClick(string text, int menuIndex, int pageIndex)
        {
            switch (menuIndex)
            {
                case 0:
                    UIStyle style = (UIStyle)pageIndex;
                    if (style != UIStyle.Colorful)
                        StyleManager.Style = style;
                    else
                        SelectPage(pageIndex);

                    break;

                default:
                    Aside.SelectPage(pageIndex);
                    break;
            }
        }

        private void FMain_Selecting(object sender, TabControlCancelEventArgs e, UIPage page)
        {
            if (page != null)
                Console.WriteLine(page.Text);
        }
    }
}